<!-- 集合消息详情 -->
<!--
 1.分为领队|组长|其他人三种角色
 2.详情内容做scrollView
 -->
<template>
  <view :style="{height : pageHeight + 'px'}" class="content">
    <!-- 详情内容 -->
    <view class="DetailList">
      <view class="tiele">
        {{ gatherData.messageAssemble.headline }}
      </view>
      <view class="sendTime">
        时间：{{ gatherData.messageAssemble.createTime }}
      </view>
      <view class="contentList">
        <view class="textContent">
          {{ gatherData.messageAssemble.content }}
          <!-- <tui-textarea placeholder="请输入内容" :value="detailContent" height=""></tui-textarea> -->

        </view>
        <view v-if="gatherData.messageAssemble.assemblePlaceUrl" class="imageContent">
          <image :src="gatherData.messageAssemble.assemblePlaceUrl" mode="aspectFit">
          </image>
        </view>
      </view>
      <view class="address">
        <image mode="aspectFit" src="https://echengtuhua.oss-cn-shenzhen.aliyuncs.com/locationPornt.png">
        </image>
        <view class="addressDes">
          {{ gatherData.messageAssemble.assemblePlaceName }}
        </view>
        <view class="navigation" @tap="openWxMap">
          <text>|</text>
          <image mode="aspectFit" src="https://echengtuhua.oss-cn-shenzhen.aliyuncs.com/locIcon2.png"></image>
          导航
        </view>
      </view>
    </view>


    <view v-if="gatherDetail&& gatherDetail.status === 1" class="isSign">
      已签到
    </view>
    <view v-else :class="roles.participant&&roles.leader === false ? 'sign':'notSign'" class="sign" @tap="signUser">
      <tui-badge :scaleRatio="1.8" absolute dot top="10rpx" translateX="-5rpx" type="danger"></tui-badge>
      签到
    </view>

    <view v-if="roles.principal || roles.leader" class="checkStatus" @tap="toSignInfo">
      查看签到情况
    </view>

  </view>
</template>

<script>
import {
  queryAssemblePersonList,
  queryAssembleDetail,
  readMessage
} from '@/api/tourplan.js'

export default {
  data() {
    return {
      pageHeight: 750,
      gatherData: [],
      roles: {},
      gatherDetail: {},
      groupId: null,
      itineraryId: 0,
      proposalId: 0,
    }
  },
  onLoad: function (options) {
    const that = this
    uni.getSystemInfo({
      success: function (res) {
        that.pageHeight = res.windowHeight
      }
    });
    that.initData(options)
  },
  methods: {
    //初始化数据
    initData(options) {
      const that = this
      const dataJSON = decodeURIComponent(options.dataGather)
      that.gatherData = JSON.parse(dataJSON)
      const rolesJSON = decodeURIComponent(options.roles)
      that.roles = JSON.parse(rolesJSON)
      that.groupId = options.groupId
      that.itineraryId = Number(options.itineraryId)
      that.proposalId = options.proposalId
      that.getGatherDetail(that.roles)
    },

    //获取消息详情
    getGatherDetail(roles) {
      const that = this
      if (roles.participant) {
        //用户
        queryAssemblePersonList({
          id: that.gatherData.id
        }).then(res => {
          that.gatherDetail = res
        }).catch(err => {
          uni.showToast({
            title: err.error,
            icon: 'none',
            duration: 3000
          })
        })
      } else {
        //领队或组长
        // queryAssembleDetail({
        // 	messageId: that.gatherData.id
        // }).then(res => {
        // 	that.gatherDetail = res
        // }).catch(err => {
        // 	uni.showToast({
        // 		title: err.error,
        // 		icon: 'none',
        // 		duration: 3000
        // 	})
        // })
      }
    },
    //用户报道
    signUser() {
      const that = this
      if (that.roles.participant && !that.roles.leader) {
        readMessage({
          messageAssembleId: that.gatherDetail.id,
          type: 1,
        }).then(res => {
          that.getGatherDetail(that.roles)
          uni.showToast({
            title: '签到成功',
            icon: 'none',
            duration: 3000
          })
        })
      } else {
        uni.showToast({
          title: '您不用签到',
          icon: 'none',
          duration: 3000
        })
      }

    },

    //唤起微信内置地图
    openWxMap() {
      const that = this
      const longitude = Number(that.gatherData.assemblePlaceY)
      const latitude = Number(that.gatherData.assemblePlaceX)
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        name: that.gatherData.assemblePlaceName,
        scale: 18,
      })
    },

    toSignInfo() {
      const that = this
      uni.navigateTo({
        url: '/pages/tourplan/noticeGather/signInfo/signInfo?gatherData=' + encodeURIComponent(
            JSON.stringify(that.gatherData)) + '&groupId=' + that.groupId + '&itineraryId=' + that
            .itineraryId + '&proposalId=' + that.proposalId
      })
    },

  }
}
</script>

<style>
@import url('./gatherDetail.css');
</style>
